package com.ebei.platform.entity;

import java.io.Serializable;
import java.util.Date;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.mapper.SqlCondition;
import com.ebei.platform.common.Constants;
import com.ebei.platform.vo.UserParams;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

/**
 * 用户Entity
 *
 * @author Victor.You@ebeitech
 * @version 1.0
 * @created 2018/7/9
 */
@Data
@TableName("user")
@SuppressWarnings("serial")
public class User extends Model<User> {

    @TableId("id")
    private String id;

    private Long tenantId;
    
    private String account;
    
    private String avatar;
    
    private String phone;
    
    /**
     * 名称 , condition 属性设置注入
     * 等效于 SQL 为：WHERE name LIKE CONCAT('%',s值,'%')
     */
    @TableField(condition = SqlCondition.LIKE)
    private String name;
    
    @TableField
    private String password;
    
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    
    private String createUserId;
    
    /**
     * 注入更新内容【可无】
     */
    @TableField(update = "now()")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;
    
    @TableField
    private String updateUserId;
    
    @TableField
    private Integer status;
    
    public User() {
    }
    
    public User(UserParams params) {
        this.account = params.getAccount();
        this.name = params.getName();
        try {
            this.status = Integer.parseInt(params.getStatus());
        } catch (NumberFormatException nfe) {
            this.status = Constants.STATUS_NORMAL;
        }
        this.phone = params.getPhone();
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
    
    public String getId() {
        return id;
    }

    @Override
    public String toString() {
        return "User [id=" + this.id + ", name=" + name
                + ", status=" + status
                + ", createTime=" + createTime  + ", createUserId=" + createUserId
                + ", updateTime=" + updateTime + ", updateUserId=" + updateUserId + "]";
    }

}
